package cn.safeness.web;

import cn.safeness.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PreAuthorize("hasRole('ADMIN')")
    @GetMapping("showtable")
    @ResponseBody
    public String login() {
        String result = accountService.login();
        return result;
    }

    @GetMapping("account")
    @ResponseBody
    public String account(Principal principal){
        return principal.getName();
    }
}
